$(function(){
	var answerId = ym.getQueryStringByName('answerId');
	var doctorId = ym.getQueryStringByName('doctorId');
	var userId = ym.getQueryStringByName('userId');
	
	function show(){
		ym.ajax({
			url: "/Answer/queryYmAnswerListDetail",
			param:{
				answerId:answerId,
				praiseType:4,
				typeId:doctorId
			},
			success: function (data){
				$('.content').html("");
				console.log(data);
				if(data.res == 1){
					var pinlunHTML="";
					pinlunHTML+= "<div class='problem-tab content-tab am-padding-bottom-0'>"
					pinlunHTML+= "<div class='person-tab-head'>"
					pinlunHTML+= "<div class='head-image'><img src='"+data.obj.ymAnswerVO.headimgurl+"' ></div>"
					pinlunHTML+= "<div class='person-name w65'>"
					pinlunHTML+= "<h4 class='person-name-text'>"+data.obj.ymAnswerVO.nickName+"</h4>"
					pinlunHTML+= "<div class='add-problem-time font13 color93 w100'><p>"+data.obj.ymAnswerVO.createTimeString+"</p></div>"
					pinlunHTML+= "</div>"
					pinlunHTML+= "<div class='problem-dianzancount w10 am-text-right' id='dianzan' praiseState='"+data.obj.ymAnswerVO.praiseState+"' answerId='"+data.obj.ymAnswerVO.answerId+"'></div>"
					pinlunHTML+= "<p class='none answerUserId'>"+data.obj.ymAnswerVO.answerUserId+"</p>"
					pinlunHTML+= "<div class='problem-pinluncount am-margin-left-xs w10 am-text-right'><p><span><img src='./../img/icon-pinglun.png'></span><sup> "+data.obj.ymAnswerVO.answersCount+"</sup></p></div>"
					pinlunHTML+= "</div>"
					pinlunHTML+= "<div class='problem-tab-desc'>"
					pinlunHTML+= "<p>"+data.obj.ymAnswerVO.answerDes+"</p>"
					pinlunHTML+= "</div>"
					pinlunHTML+= "<ul class='imgList picView-magnify-list' style='margin-left:3.8rem'>"
					if(data.obj.ymAnswerVO.ymAttachments.length > 0){
						for(var j=0;j<data.obj.ymAnswerVO.ymAttachments.length;j++){
							var zhi = data.obj.ymAnswerVO.ymAttachments[j];
							pinlunHTML+= "<li style='width:26%;overflow:hidden;display:inline-block'>"
							pinlunHTML+= "<a href='javascript:void(0)' data-magnify='gallery' data-group='g1' data-src='"+zhi.attachmentUrl+"' data-caption=''>"
							pinlunHTML+= "<img src="+zhi.attachmentUrl+" style='width:100%;height:100px'>"
							pinlunHTML+= "</a>"
							pinlunHTML+= "</li>"
						}
					}
					pinlunHTML+= "</ul>"
					pinlunHTML+= "</div>"
					pinlunHTML+= "<div>"
					if(data.obj.ymAnswerList.length >0){
						for(var k=0;k<data.obj.ymAnswerList.length;k++){
							pinlunHTML+= "<div class='problem-talk content-tab'>"
							pinlunHTML+= "<div class='problem-talk-tab'>"
							pinlunHTML+= "<div class='doctor-tab-head'>"
							pinlunHTML+= "<div class='head-image'><img src='"+data.obj.ymAnswerList[k].headimgurl+"' ></div>"
							pinlunHTML+= "<div class='person-name w85'>"
							pinlunHTML+= "<p class='person-name-text'>"+data.obj.ymAnswerList[k].nickName+"</p>"
							pinlunHTML+= "<p class='person-reply-time'>"+data.obj.ymAnswerList[k].createTimeString+"<span class='plgr' style='float: right;'><img style='width:16px;height:16px;margin-right:0.5rem' src='../img/icon-pinglun.png'>回复</span></p>"
							pinlunHTML+= "<div class='none'>"
							pinlunHTML+= "<span class='usna'>"+data.obj.ymAnswerList[k].nickName+"</span>"
							pinlunHTML+= "<span class='parentId'>"+data.obj.ymAnswerList[k].answerUserId+"</span>"
							pinlunHTML+= "</div>"
							pinlunHTML+= "</div>"
							pinlunHTML+= "</div>"
							pinlunHTML+= "<div class='problem-reply'>"
							if(data.obj.ymAnswerList[k].parentName != null){
								pinlunHTML+= "<p><span>回复<i class='color69e600 am-margin-left-xs'>"+data.obj.ymAnswerList[k].parentName+"</i></span>"+data.obj.ymAnswerList[k].answerDes+"</p>"
							}else{
								pinlunHTML+= "<p>"+data.obj.ymAnswerList[k].answerDes+"</p>"
							}
							pinlunHTML+= "</div>"
							pinlunHTML+= "</div>"
							pinlunHTML+= "</div>"
							pinlunHTML+= "</div>"
						}
					}
					pinlunHTML+= "</div>";
				$('.content').append(pinlunHTML);
				}
			}
		});
	}
	show();
		
	var a =0;
	var urls = "http://vc.nuodk.cn"+window.location.pathname+"?answerId="+answerId+"&doctorId="+doctorId+"&userId="+userId;
    $('body').on('click','.plgr',function(){
    	var name = $(this).parent().next().children('.usna').text();
    	var parentId = $(this).parent().next().children('.parentId').text();
    	$('.release').children('textarea').focus();
    	$('.release').children('textarea').attr('placeholder','回复:'+name);
    	a++;
    	$('body').on('click','.fabu',function(){
    		console.log(a);
    		if(a == 1){
    			var answerDes = $('textarea').val();
	          	if(answerDes.length!==0){
	            ym.ajax({
	                  url: "/Answer/insertYmAnswerReply",
	                  param:{
	                  		url:urls,
	                    	parentAnswerId:answerId,
	                    	answerUserId:userId,
	                    	typeId:doctorId,
	                    	answerDes:answerDes,
	                    	parentId:parentId,
	                    	type:2
	                  },
	                  success: function (data){
	                    $('textarea').val("");
	            		show();
	                  }
	              });
	          	}else{
		            $('#ceng').modal('open');
		            $('#info-text').html('回复内容不能为空');
		            window.setTimeout(function(){
		              $('#ceng').modal('close');
		              $('#info-text').html('');
		            },500)
	          	}
	    	}
    		
    	})
    })	
	$('body').on('click','.fabu',function(){
		var parentId= $('.answerUserId').text();
		if(a == 0){
    		var answerDes = $('textarea').val();
    	if(answerDes.length!==0){
			ym.ajax({
	            url: "/Answer/insertYmAnswerReply",
	            param:{
	            	url:urls,
	            	parentAnswerId:answerId,
                	answerUserId:userId,
                	typeId:doctorId,
                	answerDes:answerDes,
                	parentId:parentId,
                	type:2
	            },
	            success: function (data) {
	            	$('textarea').val("");
	            	show();
	            }
	        });
    	}else{
	      $('#ceng').modal('open');
            $('#info-text').html('回复内容不能为空');
            window.setTimeout(function(){
              $('#ceng').modal('close');
              $('#info-text').html('');
            },500)
	    	}
   	 	}
	})	
		
		
		
	$('[data-magnify]').Magnify({
		Toolbar: [
			'prev',
			'next',
			'rotateLeft',
			'rotateRight',
			'zoomIn',
			'actualSize',
			'zoomOut'
		],
		keyboard:true,
		draggable:true,
		movable:true,
		modalSize:[800,600],
		beforeOpen:function (obj,data) {
			console.log('beforeOpen')
		},
		opened:function (obj,data) {
			console.log('opened')
		},
		beforeClose:function (obj,data) {
			console.log('beforeClose')
		},
		closed:function (obj,data) {
			console.log('closed')
		},
		beforeChange:function (obj,data) {
			console.log('beforeChange')
		},
		changed:function (obj,data) {
			console.log('changed')
		}
	});
})
